package com.hmall.search.filter;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
public class MyFeginInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
/*        if (requestAttributes != null){
            HttpServletRequest request = requestAttributes.getRequest();
            String id = request.getHeader("authorization");
            if (id == null){
                id = "2";
            }
        }*/
        String id = "2";
        requestTemplate.header("authorization", id);
    }
}
